package com.wpl.controller;

import com.wpl.bean.User;
import com.wpl.bean.Workorder;
import com.wpl.common.WebResponse;
import com.wpl.service.IOrderMyService;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 我的工单
 */
@RestController
@RequestMapping("/orderMy/")
public class OrderMyController {
    @Resource
    private IOrderMyService orderMyService;
    @GetMapping("/list")
    public WebResponse getWorkorders(){

        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");

        List<Workorder> workorders = orderMyService.getWorkorders(user.getUsername());
        if (!workorders.isEmpty()) {
            return WebResponse.success(workorders);
        }else {
            return WebResponse.failed();
        }
    }
}
